package com.gree.flowable.app.tools.utils;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

/**
 * spring上下文工具类
 */
@Component
public class SpringContextUtil {
    private static ConfigurableApplicationContext applicationContext;

    //获取上下文
    public static ConfigurableApplicationContext getApplicationContext() {
        return applicationContext;
    }

    //设置上下文
    public static void setApplicationContext(ConfigurableApplicationContext applicationContext) {
        SpringContextUtil.applicationContext = applicationContext;
    }

    //通过类型获取上下文中的bean
    public static <T> T getBean(Class<T> requiredType){
        return applicationContext.getBean(requiredType);
    }


    // 获取spring.profiles.active
    public static String getActiveProfile() {
        return applicationContext.getEnvironment().getActiveProfiles()[0];
    }
}
